﻿// H5
var production = window.location.href.indexOf("webservice.cx580.com/") > -1 ? true : false; //是否为生产环境
var SVNUrl = production ? "https://webservice.cx580.com/" : "http://test-webserver.cx580.com:9071/cweb/activity/2017/10/hi/";// svn路径的正式环境和测环境
var H5SayHiOnclick = false;

//添加 css
var filerefCss = document.createElement("link");
filerefCss.rel = "stylesheet";
filerefCss.href = SVNUrl + "css/index.min.css"; //CSS的路径
var nodeFilerefCss = document.getElementsByTagName('head')[0];
nodeFilerefCss.appendChild(filerefCss);
//添加 js
var filerefJs2 = document.createElement('script')//创建标签
filerefJs2.type = "text/javascript"; //JS定义属性type的值为text/javascript
filerefJs2.src = SVNUrl + "js/index.min.js"; //JS的路径
var nodeFilerefJs2 = document.getElementsByTagName("script")[0];
nodeFilerefJs2.parentNode.insertBefore(filerefJs2, nodeFilerefJs2);

function H5SayHiFUN() {
    H5SayHiOnclick = true;
    if (document.getElementById('SayHiId')) {
        document.getElementById("SayHiId").style.display = "block";
    } else {
        //添加 div
        var div = document.createElement("div");

        //设置 div 属性，如 id
        div.setAttribute("id", "SayHiId");

        div.innerHTML = "<div id=\"closeID\" class=\"opacity\" onclick=\"closeSayHiIdFUN('SayHiId')\"></div><div id=\"markID\"></div>" +
            "<div id=\"loadingID\" class=\"loading_content\">" +
                "<img class=\"img\" src=\"" + SVNUrl + "images/load/load.gif\" alt=\"车行易违章查询代办\" />" +
            "</div>" +
            "<div id=\"specialID\"></div>";
       // setTimeout(function () {
        document.body.appendChild(div);
        // }, 100);
    }

            var keyPre = production ? '' : 'test_';
    userData.userType = getCookie(keyPre + 'userType') || TypeOfBrowser();
    userData.userId = getCookie(keyPre + 'userId') || '';
    userData.token = getCookie(keyPre + 'userToken') || '';

    initFUN(userData.userType, userData.userId, userData.token) // 初始化请求 

}
function closeSayHiIdFUN(type) {
    if (type == "SayHiId") {
        document.getElementById("SayHiId").style.display = "none";
    }
}
/** -----------------------------------------------------------
* 初始化示例
* 内置cxytjReady()函数在H5页面上，统计JS加载完毕后会自动执行cxytjReady()：*/
function cxytjReady() { //车行易统计JS加载完成后自动执行此函数

    //初始化通用数据
    window.cxytj.init({ //以下为初始化示例，可新增或删减字段
        productId: 'sayhi20171020', //产品ID
        productVersion: '1.0', //产品版本
        productUserId: '', //APP端 （设备标记ID）
        channel: TypeOfBrowser() || 'alipay', //推广渠道
        isProduction: window.location.href.indexOf('webservice.cx580.com/') > -1 ? true : false, //生产环境or测试环境：默认测试环境false
        userId: '', //用户ID
        sessionId: '', //会话ID
        ip: '', //IP地址
        longitude: '', //经度
        latitude: '' //纬度
    });
}

// 埋点事件L：ID, userType, userId,productUserId
function cxyBuryingPoint(ID, attr, userType, userId, productUserId) {

    window.cxytj.recordUserBehavior({

        productId: 'sayhi20171020', //产品ID,
        eventId: ID, //事件标记
        eventType: '2', //事件类型
        attr1: attr,//属性1
        eventTime: window.cxytj.getNowFormatDate(),  //触发时间
        channel: userType, //推广渠道
        userId: userId || '', //用户ID
        productUserId: productUserId || '', // APP
        startTime: window.cxytj.getNowFormatDate(), //开始时间
    });
}